home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * @@@BUILDINFO@@@ 17prefs.jsx 1.0.0.54 25-Feb-2005
- * Copyright 2005 Adobe Systems Incorporated
- * All Rights Reserved.
- *
- * NOTICE: All information contained herein is, and remains the property of
- * Adobe Systems Incorporated and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe Systems
- * Incorporated and its suppliers and may be covered by U.S. and Foreign
- * Patents,patents in process,and are protected by trade secret or copyright
- * law. Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained from
- * Adobe Systems Incorporated.
- **************************************************************************/
-
- // Additions to the Prefs object.
-
- // Initial preferences
- prefs.profileLevel = 0; // Disable profiling by default
- prefs.profileTiming = false; // Do not do timing by default
- prefs.profDisplayMode = 1; // Show hit count by default (0 - nothing, 1 - hits, 2 - time)
- prefs.locale = $.locale; // the default locale
- // initial Data Browser preferences
- prefs.showFunctions = false; // Controls the display of functions; set by the Functions context menu.
- prefs.showMethods = false; // Controls the display of object methods; set by the Methods context menu.
- prefs.showPredefined = false; // Controls the display of builtin predefined data; set by the Predefined context menu.
- // Other preferences
- prefs.cleanWorkspace = false; // Controls whether to start with a clean workspace
- prefs.dontBreakOnErrors = false;// set to true if runtime errors in try blocks should be ignored
- prefs.recentFiles = []; // recently opened files
-
- // The Prefs file is a file prefs.jsx located in the app data folder for the current user.
- // On Windows, this folder is C:\Documents and Settings\username\Application Data\Adobe\
- // ExtendScript Toolkit\1.0. On the Mac, this is /Users/username/Library/Application
- // Support/Adobe/ExtendScript Toolkit/1.0. This folder is also available as app.configFolder.
-
- // Load the file prefs.jsx during app startup.
-
- prefs.load = function()
- {
- var loaded = false;
- var f = new File (app.configFolder + "/prefs.jsx");
- if (f.exists)
- loaded = app.load (f);
- return loaded;
- }
-
- // Create the parent folder if not yet present.
-
- prefs.createFolder = function()
- {
- var fld = new Folder (Folder.userData + "/Adobe");
- if (!fld.exists)
- fld.create();
- fld = new Folder (fld + "/ExtendScript Toolkit");
- if (!fld.exists)
- fld.create();
- fld = new Folder (fld + "/" + app.version);
- if (!fld.exists)
- fld.create();
- return fld;
- }
-
- // Save the file prefs.jsx during app shutdown.
-
- prefs.save = function()
- {
- // set target and engine
- prefs.target = currentDebugger.target;
- prefs.engine = currentDebugger.engine;
-
- // create the prefs file
- var fld = this.createFolder();
- var f = new File (fld + "/prefs.jsx");
- if (f.open ("w"))
- {
- f.write ("// ExtendScript Toolkit Preferences as of " + new Date().toString() + "\n\n");
- f.write ("function readPrefs()\n{\n\tvar i, doc;\n");
-
- this._writeThis (f);
- // the state of the console window
- f.write ("\twindow.console.fontSize = " + window.console.fontSize + ";\n");
- f.write ("\twindow.console.wrap = " + window.console.wrap + ";\n");
-
- // position and size of the main window
- f.write ("\twindow.bounds = [" + window.normalizedBounds + "];\n");
- f.write ("\twindow.maximized = " + window.maximized + ";\n");
-
- if (!prefs.cleanWorkspace)
- this._writeDocs (f);
-
- this._writePaneInfo (f);
-
- // finally: the splitter positions
- // needs to be at the end after all panes have been arranged
- f.write ("\twindow.splitter = " + window.splitter + ";\n");
- f.write ("\twindow.leftSplitters = [" + window.leftSplitters + "];\n");
- f.write ("\twindow.rightSplitters = [" + window.rightSplitters + "];\n");
-
- if (document)
- {
- if (!prefs.cleanWorkspace)
- // set the current document
- f.write ('\tdocument = documents.find ("' + document.scriptID + '");\n');
- }
- f.write ("}\n\nreadPrefs();\n");
- if (!f.close())
- f.remove();
- }
- }
-
- // Document loader
- // This function attempts to load the document if the script ID is not bracketed
- // if bracketed, it just creates a new document. The method is called from within
- // the code generated by writeDocs()
-
- function restoreDocument (scriptID, line1, selection)
- {
- if (scriptID [0] == '/' || scriptID [0] == '~')
- {
- // must be a filespec
- var f = new File (scriptID);
- if (f.exists)
- {
- var doc = window.scripts.loadFile (f);
- if (doc)
- {
- // do not scroll, since we set the 1st visible line afterwards
- doc.setSelection (selection[0], selection[1], false);
- doc.firstVisibleLine = line1;
- }
- }
- }
- else
- Document.create (scriptID);
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Callbacks
- ////////////////////////////////////////////////////////////////////////////
-
- // Called whenever the Prefs object changes. This can be quite often!
-
- prefs.onChange = function (propertyName)
- {
- if (currentDebugger
- && propertyName == "scripts"
- && currentDebugger.target == BridgeTalk.appSpecifier)
- currentDebugger.getScripts();
- }
-
- ////////////////////////////////////////////////////////////////////////////
- // Helpers
- ////////////////////////////////////////////////////////////////////////////
-
- // Write the prefs object
-
- prefs._writeThis = function (f)
- {
- // the prefs object
- var props = this.reflect.properties;
- for (var i = 0; i < props.length; i++)
- {
- var prop = props [i];
- if (prop == "__proto__")
- continue;
-
- f.write ("\tprefs." + prop.name + " = ");
- var value = this [prop.name];
- if (value == undefined)
- continue;
- // for now, write objects as toSource()
- if (typeof value == "object")
- f.write (value.toSource() + ";\n");
- else
- {
- if (typeof value == "string")
- value = '"' + value.toString().replace (/"/g, '\\"') + '"';
- else
- value = value.toString();
- f.write (value + ";\n");
- }
- }
- }
-
- // Write the list of documents along with the code to reload them.
- // Do not write any documents that contain scripts that were not loaded
- // from disk.
-
- prefs._writeDocs = function (f)
- {
- for (var i = 0; i < documents.length; i++)
- {
- var doc = documents [i];
- // use either the path or the title
- // when loading, a string starting with a slash indicates a path
- if (doc.scriptID [0] == '/' || doc.scriptID [0] == '~')
- f.write ('\trestoreDocument (\"'
- + doc.scriptID
- + '", '
- + doc.firstVisibleLine
- + ', ['
- + doc.getSelection()
- + ']);\n');
- else if (doc.scriptID [0] == '(')
- f.write ('\tDocument.create (\"'
- + doc.title
- + '", "", "'
- + doc.scriptID
- + '");\n');
- if (doc.scriptID [0] != '(')
- doc.writeBP (f);
- }
- }
-
- // Write the locations of all panes.
- // this is more complicated, since the tabs need to be sorted in
- // enclosure/dock/tab order - you can only append docks, not create
- // empty ones
-
- prefs._writePaneInfo = function (f)
- {
- // sort the positional info by enclosure, dock and tab
- function sortInfo (a, b)
- {
- var res = a[0] - b[0];
- if (!res)
- res = a[1] - b[1];
- if (!res)
- res = a[2] - b[2];
- return res;
- }
-
- // Collect the objects into infoArray, holding the pane info plus the object itself
- var infoArray = [];
- for (var i = 0; i < window.panes.length; i++)
- {
- var value = window.panes [i].paneInfo;
- // add the object
- value.push (window.panes [i]);
- infoArray.push (value);
- }
- // now sort this array
- infoArray.sort (sortInfo);
- // make sure that all panes are hidden so we can rebuild the layout from scratch
- f.write ("\tfor (i = 0; i < window.panes.length; i++)\n");
- f.write ("\t\twindow.panes [i].visible = false;\n");
- // and write the results
- for (i = 0; i < infoArray.length; i++)
- {
- value = infoArray [i];
- var obj = value.pop();
- if (obj.constructor.name == "Document")
- {
- // a document pane
- if (!prefs.cleanWorkspace)
- f.write ('\tdoc = documents.find ("'
- + obj.scriptID
- + '");\n'
- + '\tif (doc) doc.paneInfo = [' +
- value + "];\n");
- }
- else
- {
- // a pane
- f.write ("\tif (window." + obj.name + ")\n");
- f.write ("\t\twindow." + obj.name + ".paneInfo = [" + value + "];\n");
- }
- }
- // Select the previously selected panes
- for (var i = 0; i < window.panes.length; i++)
- {
- obj = window.panes [i];
- if (!(obj instanceof Document) && obj.selected)
- f.write ("\twindow." + obj.name + ".selected = true;\n");
- }
- if (!prefs.cleanWorkspace)
- {
- for (i = 0; i < documents.length; i++)
- {
- obj = documents [i];
- if (obj.selected)
- {
- f.write ('\tdoc = documents.find ("' + obj.scriptID + '");\n');
- f.write ('\tif (doc) doc.selected = true;\n');
- }
- }
- }
- }
-